package com.yanggu.scala.chapater11.exercise;

import java.util.HashMap;
import java.util.Map;

/**
 * @version V1.0
 * @author: YangGu
 * @date: 2020/7/13 13:53
 * @description:
 */
public class JavaWordCount {

    public static void main(String[] args) {
        //val sentence = "AAAAAAAAAABBBBBBBBCCCCCDDDDDDD"
        //使用映射集合，统计一句话中，各个字母出现的次数
        String sentence = "AAAAAAAAAABBBBBBBBCCCCCDDDDDDD";
        Map<Character, Integer> map = new HashMap<Character, Integer>();
        for (int i = 0; i < sentence.length(); i++) {
            char c = sentence.charAt(i);
            Integer count = map.get(c);
            if (count == null) {
                map.put(c, 1);
            } else {
                map.put(c, count + 1);
            }
        }
        System.out.println(map);
    }

}
